TaskStackBuilder

Utility class for constructing synthetic back stacks for cross-task navigation on Android 3.0 and newer.

In API level 11 (Android 3.0/Honeycomb) the recommended conventions for app navigation using the back key changed. The back key's behavior is local to the current task and does not capture navigation across different tasks. Navigating across tasks and easily reaching the previous task is accomplished through the "recents" UI, accessible through the software-provided Recents key on the navigation or system bar. On devices with the older hardware button configuration the recents UI can be accessed with a long press on the Home key.

When crossing from one task stack to another post-Android 3.0, the application should synthesize a back stack/history for the new task so that the user may navigate out of the new task and back to the Launcher by repeated presses of the back key. Back key presses should not navigate across task stacks.

TaskStackBuilder provides a backward-compatible way to obey the correct conventions around cross-task navigation on the device's version of the platform. On devices running Android 3.0 or newer, calls to the startActivities method or sending the PendingIntent generated by getPendingIntent will construct the synthetic back stack as prescribed. On devices running older versions of the platform, these same calls will invoke the topmost activity in the supplied stack, ignoring the rest of the synthetic stack and allowing the back key to navigate back to the previous task.

### About Navigation For more detailed information about tasks, the back stack, and navigation design guidelines, please read from the developer guide and from the design guide.

Types

Link copied to clipboard

Functions

Link copied to clipboard
@NonNull
open fun addNextIntent(@NonNull nextIntent: @NonNull Intent): @NonNull TaskStackBuilder
Add a new Intent to the task stack.
Link copied to clipboard
@NonNull
open fun addNextIntentWithParentStack(@NonNull nextIntent: @NonNull Intent): @NonNull TaskStackBuilder
Add a new Intent with the resolved chain of parents for the target activity to the task stack.
Link copied to clipboard
@NonNull
open fun addParentStack(@NonNull sourceActivity: @NonNull Activity): @NonNull TaskStackBuilder
@NonNull
open fun addParentStack(@NonNull sourceActivityName: @NonNull ComponentName): @NonNull TaskStackBuilder
@NonNull
open fun addParentStack(@NonNull sourceActivityClass: @NonNull Class<out Any>): @NonNull TaskStackBuilder
Add the activity parent chain as specified by manifest elements to the task stack builder.
Link copied to clipboard
@NonNull
open fun create(@NonNull context: @NonNull Context): @NonNull TaskStackBuilder
Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.
Link copied to clipboard
@Nullable
open fun editIntentAt(index: Int): @Nullable Intent
Return the intent at the specified index for modification.
Link copied to clipboard
open fun from(context: Context): TaskStackBuilder
Return a new TaskStackBuilder for launching a fresh task stack consisting of a series of activities.
Link copied to clipboard
open fun getIntent(index: Int): Intent
Get the intent at the specified index.
Link copied to clipboard
open fun getIntentCount(): Int
Link copied to clipboard
open fun getIntents(): @NonNull Array<Intent>
Return an array containing the intents added to this builder.
Link copied to clipboard
@Nullable
open fun getPendingIntent(requestCode: Int, flags: Int): @Nullable PendingIntent
@Nullable
open fun getPendingIntent(requestCode: Int, flags: Int, @Nullable options: @Nullable Bundle): @Nullable PendingIntent
Obtain a PendingIntent for launching the task constructed by this builder so far.
@Nullable
open fun getPendingIntent(requestCode: Int, flags: Int, isMutable: Boolean): @Nullable PendingIntent
@Nullable
open fun getPendingIntent(requestCode: Int, flags: Int, @Nullable options: @Nullable Bundle, isMutable: Boolean): @Nullable PendingIntent
Obtains a PendingIntent with mandatory mutability flag set on supported platform versions.
Link copied to clipboard
@NonNull
open fun iterator(): @NonNull Iterator<Intent>
Link copied to clipboard
open fun startActivities()
open fun startActivities(@Nullable options: @Nullable Bundle)
Start the task stack constructed by this builder.